package generics;

import java.util.ArrayList;

/**
 * 泛型支持的类型
 */
public class GenericDemo6 {
    public static void main(String[] args) {
        //泛型不支持基本数据类型
        //ArrayList<double> list = new ArrayList<>();
        //把基本数据类型变成包装类对象
        //Integer i = new Integer(10);
        //-128~127  共享模式
        //手动完成
        Integer it1 = Integer.valueOf(100);
        Integer it2 = Integer.valueOf(100);
        System.out.println(it1 == it2);
        //自动装箱
        Integer it3 = 130;
        Integer it4 = 130;
        System.out.println(it3 == it4);

        //自动拆箱
        int i = it3;
        int j = it4;
        System.out.println(i == j);

        //自动装箱
        ArrayList<Integer> list = new ArrayList<>();
        list.add(100);
        list.add(200);
        list.add(300);
        //自动拆箱
        int i1 = list.get(1);
        System.out.println("------------------------");
        //包装类新增的功能
        //数值类型转字符串
        int k = 23;
        String rs1 = Integer.toString(k);
        System.out.println(rs1 + 1);
        Integer k2 = 34;
        String rs2 = k2.toString();
        System.out.println(rs2 + 1);

        Integer k3 = 56;
        String rs3 = k3 + "";
        System.out.println(rs3 + 1);//561-->字符串后接数字还是字符串
        System.out.println("------------------------");
        //把字符串转数值类型
        String str = "98";
        int rs4 = Integer.parseInt(str);
        System.out.println(rs4 + 1);
        Integer rs5 = Integer.valueOf(str);
        System.out.println(rs5 + 1);
        System.out.println("------------------------");
        String str2 = "89.7";
        double rs6 = Double.parseDouble(str2);
        System.out.println(rs6 + 1);
        Double rs7 = Double.valueOf(str2);
        System.out.println(rs7 + 1);




    }
}
